<template>
  <div
    class="travel_list"
    @mouseleave="PageIndex = -1"
    v-if="PageList"
  >
    <div class="travel_listss">
      <ul>
        <li
          :class="{
            'active' : PageIndex == index
         }"
          v-for="(item,index) in PageList"
          :key="index"
          @mouseover="PageIndex = index"
        >{{item.type}}

          <span class="el-icon-arrow-right"></span>
        </li>
      </ul>
      <div
        class="travel_tiave"
        v-if="PageIndex !== -1"
      >
        <div
          class="ctive"
          v-for="(item,index) in PageList[PageIndex].children"
          :key="index"
        >
          <div class="nub">{{index + 1}}</div>
          <div
            class="city"
            @click="Trriger(item.city)"
          >{{item.city}}</div>
          <div
            class="desc"
            @click="Trriger(item.city)"
          >{{item.desc}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { log } from "util";
export default {
  data() {
    return {
      PageIndex: -1,
      PageList: null,
    };
  },
  async created() {
    //获取热门城市列表列表
    const res = await this.$axios.get("/posts/cities");
    console.log(res);
    this.PageList = res.data.data;
  },
  methods: {
    //触发父组件里面的函数
    Trriger(val) {
      console.log(val);
      this.$emit("triggerSeach", val);
    },
  },
};
</script>

<style lang="less" scoped>
.travel_list {
  .travel_listss {
    position: relative;
    ul {
      position: relative;
      z-index: 999;
      margin-bottom: 20px;
      li {
        width: 260px;
        height: 40px;
        font-size: 16px;
        color: #333;
        border: 1px solid #ddd;
        border-bottom: none;
        padding: 0 20px;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
        &:last-child {
          border-bottom: 1px solid #ddd;
        }
        span {
          text-align: right;
        }
      }
      .active {
        color: orange;
        border-right: 1px solid #fff;
      }
      // li:hover {

      // }
    }
    .travel_tiave {
      width: 500px;
      position: absolute;
      left: 239px;
      top: 0;
      z-index: 3;
      border: 1px solid #ddd;
      background-color: #fff;
      padding: 10px 5px;
      margin-left: 20px;
      .ctive {
        display: flex;
        align-items: center;
        height: 34px;
        .nub {
          width: 40px;
          text-align: center;
          color: #ffa500;
          font-size: 24px;
          font-style: oblique;
        }
        .city {
          font-size: 14px;
          color: #ffa500;
          width: 50px;
          padding-left: 2px;
          font-weight: normal;
          cursor: pointer;
          &:hover {
            color: orange;
            text-decoration: underline;
          }
        }
        .desc {
          font-size: 14px;
          font-weight: normal;
          color: #777;
          cursor: pointer;
          &:hover {
            color: orange;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
</style>